﻿<Window x:Class="RequirementLogger.Appl.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:VM="clr-namespace:RequirementLogger.Appl.ViewModels"
        xmlns:conv="clr-namespace:RequirementLogger.Appl.Converters"
        Height="350" Width="525">

    <Grid Name="LayoutRoot">
        <Grid.Resources>
            <VM:MainViewModel x:Key="MainVM" />
            <conv:VisibilityConverter x:Key="VisibilityConverter" />
            <conv:PropertyInfoConverter x:Key="PropertyInfoConverter" />
        </Grid.Resources>

        <Grid Name="grdDefaultLayout" DataContext="{StaticResource MainVM}" Margin="10">
            <Grid.RowDefinitions>
                <RowDefinition Height="50" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <StackPanel Name="stkApps" Orientation="Vertical" Margin="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
                <TextBlock Name="lblApps" Text="Select application.." Margin="0,0,0,3" />
                <Grid Name="grdEditApps">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition Name="colEdit" Width="65" />
                        <ColumnDefinition Name="colClear" Width="30" />
                    </Grid.ColumnDefinitions>
                    <ComboBox Name="cmbAppNames" Margin="0,0,3,0" 
                              ItemsSource="{Binding AllApplications}" 
                              SelectedItem="{Binding SelectedApp, Mode=TwoWay}"
                              DisplayMemberPath="AppName" SelectedValuePath="AppId" />
                    <ToggleButton Name="btnEdit" Grid.Column="1" Content="Edit/Add" HorizontalAlignment="Right" 
                                  IsChecked="{Binding EditClicked, Mode=TwoWay}" />
                    <ToggleButton Name="btnClear" Grid.Column="2" Content="X" Foreground="Red" FontWeight="Bold" 
                                  HorizontalAlignment="Right" 
                                  IsChecked="{Binding ClearClicked, Mode=TwoWay}" />
                </Grid>
            </StackPanel>

            <Grid Name="grdAppEditor" Grid.ColumnSpan="2" Grid.Row="1"  Visibility="{Binding IsAppEditorVisible, Converter={StaticResource VisibilityConverter}}">
                <Grid.RowDefinitions>
                    <RowDefinition />
                </Grid.RowDefinitions>

                <Grid Name="stkAppEditor" >
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="30" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>

                    <ItemsControl Name="itmctrlAppEditor1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                  ItemsSource="{Binding AllAppEditorProperties, Mode=TwoWay}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <ItemsControl Name="itmctrlAppEditor2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                              ItemsSource="{Binding PropertyCollection}">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <Grid Name="grdAppEditorTemplate">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="150" />
                                                    <ColumnDefinition />
                                                </Grid.ColumnDefinitions>

                                                <TextBlock Name="lblPropertyName" Margin="0,0,5,0" 
                                                           Text="{Binding PropertyName}" TextAlignment="Right" 
                                               HorizontalAlignment="Right" VerticalAlignment="Center" />
                                                <TextBox Name="txtPropertyValue" Grid.Column="1" Margin="5,0,0,0" 
                                                         Text="{Binding PropertyValue}" TextAlignment="Left" />
                                            </Grid>
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <ItemsControl Name="itmctrlAppEditorTEST" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                  ItemsSource="{Binding SelectedApp, Converter={StaticResource PropertyInfoConverter}}">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Grid Name="grdAppEditorTemplate2">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="150" />
                                        <ColumnDefinition />
                                    </Grid.ColumnDefinitions>

                                    <TextBlock Name="lblPropertyName2" Margin="0,0,5,0" 
                                               Text="{Binding PropertyName}" TextAlignment="Right" 
                                               HorizontalAlignment="Right" VerticalAlignment="Center" />
                                    <TextBox Name="txtPropertyValue2" Grid.Column="1" Margin="5,0,0,0" 
                                             Text="{Binding PropertyValue}" TextAlignment="Left" />
                                </Grid>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                    <StackPanel Name="stkButtons" Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center">
                        <Button Name="btnExitEditor" Content="Exit" Margin="0,0,3,0" />
                        <Button Name="btnSaveEditor" Content="Save" Margin="3,0,3,0" />
                        <Button Name="btnResetEditor" Content="Reset" Margin="3,0,0,0" />
                    </StackPanel>
                </Grid>
            </Grid>
        </Grid>
    </Grid>
</Window>
